#include<iostream>
#include<vector>
using namespace std;


class Solution {
public:
    vector<int> partitionLabels(string s) {
        int len = s.size();
        vector<int> tmpVt;
        vector<int> ans;
        tmpVt.resize(len);
        for (int i = 0; i < len; i++) {
            char ch = s[i];
            for (int j = len - 1; j >= 0; j--) {
                if (ch == s[j]) {
                    tmpVt[i] = j;
                    break;
                }
            }
        }
        for (int i = 0; i < len; i++) {
            int n = tmpVt[i];
            for (int j = i + 1; j <= n; j++) {
                if (tmpVt[j] > n) {
                    n = tmpVt[j];
                }
            }
            ans.push_back(n - i + 1);
            i = n;
        }
        return ans;
    }
};